<?php


namespace App\Repository;

use App\Models\LoginWeb;
use Illuminate\Database\Eloquent\Builder;

class LoginRepository extends BaseRepository
{
    /**
     * @param $loadData
     * @return Builder|\Illuminate\Database\Eloquent\Model
     */
    public function create($loadData)
    {
        $login = new LoginWeb();

        return $login::getInstance()->create($loadData);
    }

    /**
     * @param LoginWeb $login
     * @param $loadData
     * @return int
     */
    public function resetToken($login, $loadData)
    {
        return $login::getInstance()
            ->where('user_id', $login->user_id)
            ->update($loadData);
    }


    /**
     * 通过accessToken获取登录令牌信息
     * @param string $accessToken
     * @param array $fields
     * @return Builder|LoginWeb|object|null
     */
    public function getLoginByAccessToken($accessToken, $fields = ['*'])
    {
        return LoginWeb::getInstance()
            ->select($fields)
            ->where('access_token', $accessToken)
            ->first();
    }
}
